// pages/addStick/addStick.js
let network = require("../../utils/network/network.js")
let api = require("../../utils/network/config.js").api;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    stickName: '',
    stickPrice: 1,
    stickList: '',

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getStickList()
  },
  saveStick() {
    let that = this
    if (that.data.stickName == '') {
      wx.showToast({
        title: '竹签名称不能为空',
        icon: 'none',
        duration: 1800
      })
      return
    }
    if (that.data.stickPrice == '') {
      wx.showToast({
        title: '竹签价格不能为空',
        icon: 'none',
        duration: 1800
      })
      return
    }

    let params = {
      stickName: that.data.stickName,
      stickPrice: that.data.stickPrice * 100,
      shopId: 1
    }
    network.fetch({
        url: api.stick_save,
        inBody: true,
        data: params,
        method: 'POST',
      })
      .then(res => {
        console.log(res)
        that.getStickList()
      })
  },
  getStickList() {
    let that = this
    network.fetch({
        url: api.stick_list,
        inBody: false,
        data: {
          //userId: getApp().globalData.userInfo.uid
          userId: 22
        },
        method: 'GET',
      })
      .then(res => {
        let stickList = res.data

        that.setData({
          stickList: res.data,
        })
      })
  },

})